package com.example.android_mvp_one.mvp.view.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.TextView;

import com.example.android_mvp_one.R;
import com.example.android_mvp_one.di.component.DaggerLruComponent;
import com.example.android_mvp_one.di.modules.LreModules;
import com.example.android_mvp_one.mvp.control.LreControl;
import com.example.android_mvp_one.mvp.model.entity.BaseEntitiy;
import com.example.android_mvp_one.mvp.presenter.LruPresenter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jwenfeng.library.pulltorefresh.BaseRefreshListener;
import com.jwenfeng.library.pulltorefresh.PullToRefreshLayout;

import butterknife.BindView;

public class MainActivity extends BaseActivity<LruPresenter> implements LreControl.LruControlView, BaseRefreshListener {

    @BindView(R.id.main_text)
    TextView text;
    @BindView(R.id.main_refresh)
    PullToRefreshLayout refresh;
    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerLruComponent.builder().appComponent(appComponent)
                .lreModules( new LreModules(this))
                .build().inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_main;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        refresh.setRefreshListener(this);

        mPresenter.postNetWork();
    }

    @Override
    public void onSucceed(BaseEntitiy entitiy) {

        text.setText( entitiy.toString());
    }
    @Override
    public void showMessage(@NonNull String message) {
        Log.e(TAG, "showMessage: " + message );
    }

    /**
     * 上下拉刷新
     */
    @Override
    public void refresh() {

        refresh.finishRefresh();
    }

    @Override
    public void loadMore() {

        refresh.finishLoadMore();
    }
}
